package com.housesales.thread;

import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimerTask;

import module.Customers;
import module.RequirementHouse;

import org.apache.log4j.Logger;

import utils.DateUtil;
import bussinessService.basicbussinessService;
import bussinessService.impl.RequirementHouseBussinessServiceImpl;
import domain.vo.CustomerVO;
import domain.vo.RequirementHousVO;
/**
 * 
* @ClassName: MyTimerTask
* @Description: 定时器
* @author chenchao
* @date 2013-12-12 上午02:37:08
*
 */
public class MyTimerTask extends TimerTask {
	private static Logger logger = Logger.getLogger(MyTimerTask.class);
	/**
	 * 期限
	 */
	private int overdue ;
	/**
	 * 房屋客户业务层实例
	 */
	private basicbussinessService<RequirementHouse,RequirementHousVO> reqBIS = new RequirementHouseBussinessServiceImpl();
	
	/**
	 * 构造函数
	 * @param overdue
	 */
	public MyTimerTask(int overdue) {
		this.overdue = overdue;
	}

	public void run() {
		try {
			List<RequirementHousVO> list =  reqBIS.getAll();
			
			Calendar calendar = Calendar.getInstance();
			Date now = calendar.getTime();
			for(RequirementHousVO re:list) {
				if ((overdue - DateUtil.diffDate(now, re.getCreateTimeDate())) <= 0 ){
					RequirementHouse req = new RequirementHouse();
					req.setReqId(re.getReqId());
					req.setProperty(RequirementHouse.PUBLIC);
					reqBIS.merageObject(req);
				}
			}

		} catch (SQLException e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			
		}
		
	}
}
